package com.woniuxy.login.controller;

import com.woniuxy.common.CommonResult;
import com.woniuxy.login.service.UserService;
import com.woniuxy.login.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Date: 2021/6/30:11:59  <br/>
 * Description:
 */
@RestController
@RequestMapping("/login")
@Api(tags = "登陆接口")
public class LoginController {

    @Resource
    private UserService userService;


    /**
     * Description : 登陆  <br/>
     * ChangeLog : 1. 创建 (2021/7/1 12:02 [Hello Mr. Guo]);
     * @param userVo
     * @return com.woniuxy.common.CommonResult
    */
    @ApiOperation("登陆接口")
    @PostMapping("/subLogin")
    public CommonResult subLogin(@RequestBody UserVo userVo){
        String token = userService.login(userVo);
        if (StringUtils.isEmpty(token)){
            return CommonResult.fail("登录失败");
        }

        return CommonResult.success(token);
    }
}
